package com.osig.ec.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.osig.common.persistence.Page;
import com.osig.ec.entity.MaAchieveCompare;
import com.osig.ec.entity.MaProduct;
import com.osig.ec.service.MaProductService;
import com.osig.sys.dao.MaAchieveCompareDao;
import com.osig.sys.dao.MaProductDao;


@Service
public class MaProductServiceImpl implements MaProductService{

	@Autowired
	MaProductDao maProductDao;
	
	@Autowired
	MaAchieveCompareDao maAchieveCompareDao;
	
	@Transactional(readOnly = true )
	public Page<MaProduct> findList(Page<MaProduct> page, MaProduct entity) {
		entity.setPage(page);
		List<MaProduct> list = maProductDao.findList(entity);
		page.setList(list);
		return page;
	}

	@Transactional(readOnly = false )
	public int insert(MaProduct entity) {
		// TODO Auto-generated method stub
		entity.preInsert();
		for(MaAchieveCompare achieveCompare : entity.getAchieveCompares()){
			achieveCompare.preInsert();
			achieveCompare.setProductId(entity.getId());
		}
		int i = maProductDao.insert(entity);
		maAchieveCompareDao.addbatch(entity);
		return i;
	}
	
	@Transactional(readOnly = false )
	public int update(MaProduct entity) {
		// TODO Auto-generated method stub
		
		return maProductDao.update(entity);
	}
	@Transactional(readOnly = false )
	public int delete(MaProduct entity) {
		// TODO Auto-generated method stub
		return maProductDao.delete(entity);
	}

}
